package com.elin4it.ssm.service;

import com.elin4it.ssm.mapper.UserinfoMapper;
import com.elin4it.ssm.pojo.Userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Author:TY
 * @Descroption:
 * @Date: Created in 10:20 2018/4/9
 * @Modificd By:
 */
@Service("UserinfoService")
public class UserinfoServiceimpl implements UserinfoService {
    @Autowired
    UserinfoMapper userinfoMapper;
    public void insert(Userinfo userinfo) {
        userinfoMapper.insert(userinfo);
    }

    public void updateStatusToZero(String openid) {
        userinfoMapper.updateStatusToZero(openid);
    }

    public List<Userinfo> selectRival() {
        List<Userinfo> list=userinfoMapper.selectRival();
        return  list;
    }
    public  List getRandomList(List paramList, int count){
        if(paramList.size()<count){
            return paramList;
        }
        Random random=new Random();
        List<Integer> tempList=new ArrayList<Integer>();
        List<Object> newList=new ArrayList<Object>();
        int temp=0;
        for(int i=0;i<count;i++){
            temp=random.nextInt(paramList.size());//将产生的随机数作为被抽list的索引
            if(!tempList.contains(temp)){
                tempList.add(temp);
                newList.add(paramList.get(temp));
            }
            else{
                i--;
            }
        }
        return newList;
    }

    public void updateStatusToOne(String openid) {
        userinfoMapper.updateStatusToOne(openid);
    }
}
